package com.example.rahukalam;

import java.sql.Date;
import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.text.format.Time;
import android.view.Menu;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.Toast;

public class RahuKalam extends Activity {
	public final static String EXTRA_MESSAGE = "com.example.RahuKalam.MESSAGE";

	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rahu_kalam);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_rahu_kalam, menu);
        return true;
    }
    /** Called when the user clicks the Send button */
    public void sendMessage(View view) {
        // Do something in response to button
    	///Intent intent = new Intent(this, DisplayMessageActivity.class);
    	///EditText editText = (EditText) findViewById(R.id.edit_message);
    	///String message = editText.getText().toString();
    	///intent.putExtra(EXTRA_MESSAGE, message);
    	///startActivity(intent);
    	Calendar cal = Calendar.getInstance();
    	int iDay,iMonth,iYear;
	         iDay = cal.get(Calendar.DAY_OF_MONTH);
	         iMonth = cal.get(Calendar.MONTH);
	         iYear = cal.get(Calendar.YEAR);
    	DatePickerDialog dateDlg = new DatePickerDialog(this, 
   	         new DatePickerDialog.OnDateSetListener() {
   	          
   	         public void onDateSet(DatePicker view, int year,
   	                                             int monthOfYear, int dayOfMonth) 
   	         {
   	        	
   	         
   	         
   	                    Time chosenDate = new Time();
   	                    chosenDate.set(dayOfMonth, monthOfYear, year);
   	                 String dayOfWeek = DateFormat.format("EE", new Date(year, monthOfYear, dayOfMonth)).toString();
   	                    long dtDob = chosenDate.toMillis(true);
   	                    CharSequence strDate = DateFormat.format("MMMM dd, yyyy", dtDob);
   	                     String RahuKalam = "";
   	                  String ActDayOfWeek = "";
   	                    		 if (dayOfWeek.contains("Tue")) {
   	                    		 //Mon
   	                    			ActDayOfWeek = "Monday";
   	                    			RahuKalam = "7:30 AM to 9:00 AM";
   	                    		 }
   	                    		 else if (dayOfWeek.contains("Wed")) {
   	                    		//Tue
   	                    			ActDayOfWeek = "Tuesday";
   	                    			RahuKalam = "3:00 PM to 4:30 PM";
   	                    		 }
   	                    		else if (dayOfWeek.contains("Thu")) {
   	                    		//Wed 
   	                    			ActDayOfWeek = "Wednesday";
   	                    			RahuKalam = "12:00 PM to 1:30 PM";
  	                    		 }
   	                    		else if (dayOfWeek.contains("Fri")) {
   	                    		//Thu 
   	                    			ActDayOfWeek = "Thursday";
   	                    			RahuKalam = "1:30 PM to 3:00 PM";
  	                    		 }
   	                    		else if (dayOfWeek.contains("Sat")) {
   	                    		//Fri 
   	                    			ActDayOfWeek = "Friday";
   	                    			RahuKalam = "10:30 AM to 12:00 PM";
   	                    			
  	                    		 }
   	                    		else if (dayOfWeek.contains("Sun")) {
   	                    		//Sat 
   	                    			ActDayOfWeek = "Saturday";
   	                    			RahuKalam = "9:00 AM to 10:30 AM";
  	                    		 }
   	                    		else if (dayOfWeek.contains("Mon")) {
   	                    		//Sun 
   	                    			ActDayOfWeek = "Sunday";
   	                    			RahuKalam = "4:30 PM to 6:00 PM";
  	                    		 }
   	                    		else {
   	                    			RahuKalam = "ERROR";
   	                    		}
   	                    Toast.makeText(RahuKalam.this, 
   	                         "Rahu Kalam on: " + strDate + " and Day: " + ActDayOfWeek + " is from: " + RahuKalam, Toast.LENGTH_LONG).show();
   	        }}, 2011,0, 1);
    	dateDlg.updateDate(iYear, iMonth, iDay);       
   	      dateDlg.setMessage("Select date to check Rahu Kalam");
   	      dateDlg.show();
    	
    }
}
